package com.crm.service.impl;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.crm.entity.Module;
import com.crm.repository.ModuleRepository;
import com.crm.service.ModuleService;
@Service
public class ModuleServiceImpl implements ModuleService {
	@Autowired
	private ModuleRepository moduleRepository;

	@Override
	public List<Module> getUser_Role_ModuleByUserId(String id) {
		// TODO Auto-generated method stub
		return moduleRepository.getUser_Role_ModuleByUserId(id);
	}

	@Override
	public List<Module> GetAll() {
		// TODO Auto-generated method stub
		return moduleRepository.findAll();
	}

	@Override
	public String AddAndUpdateModule(Module module) {
		// TODO Auto-generated method stub
		try {
			moduleRepository.saveAndFlush(module);
			return "操作成功";
		} catch (Exception e) {
			// TODO: handle exception
			return "操作失败";
		}
		
	}

	@Override
	public String DeleteModuleById(Integer id) {
		// TODO Auto-generated method stub
		try {
			moduleRepository.deleteById(id);
			return "删除成功";
		} catch (Exception e) {
			// TODO: handle exception
		}
		return "删除失败";
	}
    @Transactional
	@Override
	public Integer updateTree(String name, String path, Integer weight, Integer id) {
		// TODO Auto-generated method stub
		return moduleRepository.updateTree(name, path, weight, id);
	}

}
